package HelloSeries.ui.prefs.elems.flextables.editor;

import java.awt.Color;
import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellEditor;

public class TextEditor extends AbstractCellEditor implements TableCellEditor{
	protected JTextField textfield;
	private String    content;

	public TextEditor() {
		super();
		textfield = new JTextField();
	}


	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		textfield = (JTextField) value;
		content = textfield.getText();
		if (isSelected) {
			textfield.setForeground(table.getSelectionForeground());
			textfield.setBackground(Color.GRAY);
		} else{
			textfield.setForeground(table.getForeground());
			textfield.setBackground(table.getBackground());
		}
		return textfield;
	}


	public Object getCellEditorValue() {
		content = textfield.getText();
		return content;
	}
	
	
	public boolean stopCellEditing() {
		content = textfield.getText();
		if (content.equals("")) super.cancelCellEditing();
		return super.stopCellEditing();
	}
}
